/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.yonsei.iwb.smarttv.querygraph.algorithm;

import com.hp.hpl.jena.graph.Node;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.Resource;
import edu.yonsei.iwb.smarttv.model.MArc;
import edu.yonsei.iwb.smarttv.model.MNode;
import edu.yonsei.iwb.smarttv.querygraph.VariableMap;
import java.util.Vector;

/**
 *
 * @author Onlyjiny
 */
public class ShortestPath extends Vector<MArc> {
    private VariableMap vm;
    private double score;
    
    public void setPathScore(){
        double s = 0;
        for (int i = 0; i < this.size(); i++) {
            MArc arc = this.get(i);
            double w = arc.getWeight();
            s = s + w;
        }
        this.score = s;
    }
    
    public double getPathScore(){
//        return this.score;
        this.setPathScore();
        return this.score;
    }
    
    public Vector<Property> getAllPropertySet(){
        Vector<Property> pset = new Vector<Property>();
        for (int i = 0; i < this.size(); i++) {
            MArc arc = this.get(i);
            if(!pset.contains(arc.getProperty())){
                pset.add(arc.getProperty());
            }
        }
        return pset;
    }
    
    public void setVariableMap(VariableMap variableMap){
        this.vm = variableMap;
    }
    
    public VariableMap getVariableMap(){
        return this.vm;
    }
    
    public Node getVariableNodeByResource(Resource r){
        return vm.getVariablesAsClass(r).firstElement();
    }
        
    @Override
    
    // 이부분 다시 작성해주어야 함.
    public String toString() {
        StringBuffer sb = new StringBuffer();
                
        for(int i = 0; i < this.size(); i++) {
            MArc marc = this.get(i);
            sb.append(marc.toString());            
        }        
        sb.append("\n");
        return sb.toString();
    }
}
